<template>
	<view class="pd pm200">
		<view class="kxczxcstreszxr pd pt30 pm20 mt20">
			<view class="fz32 display-flex pr">
				<view class="flex-1">
					<text class="kkxczxerwt">基本信息</text>
				</view>
			</view>
			<view class="btm mt20 pt20">
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl">
						公司名称:
					</view>
					<view class="z3 flex-1">
						<input v-model="dataForm.companyName" type="text" class="kxcxzrtrtxr pl20"
							placeholder="请输入公司名称" />
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6 btm pt20 pm20" @tap="dimxd">
					<view class="xczvrytxctrtr vertical-center tl">
						公司地址:
					</view>
					<view class="z3 flex-1">
						<text class="z3" v-if="dataForm.companyAddr">{{dataForm.companyAddr}}</text>
						<text class="z9" v-else>请选择公司地址</text>
					</view>
					<view class=" vertical-center">
						<text class="iconfont icon-rightyou"></text>
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6 btm">
					<view class="xczvrytxctrtr vertical-center tl">
						联系人:
					</view>
					<view class="z3 flex-1">
						<input v-model="dataForm.linkMan" type="text" class="kxcxzrtrtxr pl20" placeholder="请输入联系人" />
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6 btm">
					<view class="xczvrytxctrtr vertical-center tl">
						联系电话:
					</view>
					<view class="z3 flex-1">
						<input v-model="dataForm.linkManTel" type="tel" class="kxcxzrtrtxr pl20"
							placeholder="请输入联系电话" />
					</view>
				</view>

				<view class="btm pt20">
					<textarea v-model="dataForm.content" placeholder="请输入公司简介" class="fcvvxxcvyty"></textarea>
				</view>
			</view>
		</view>


		<view class="kxczxcstreszxr pd pt30 pm20 mt20">
			<view class="fz32 display-flex pr">
				<view class="flex-1">
					<text class="kkxczxerwt">其他</text>
				</view>
			</view>
			<view class="btm mt20 ">
				<view class="pt10 pm10 display-flex fz30 z6 ">
					<view class="xczvrytxctrtr  vertical-center tl">
						企业类型:
					</view>
					<view class="z3 flex-1">
						<radio-group class="" @change="jxczertet">
							<label class="xzczxctrt mr20" v-for="item in jnxcdfr">
								<view class="display-flex">
									<view>
										<radio :checked="dataForm.tag==item.dictValue?true:false"
											:value="item.dictValue" class="kcxzvxcdrytr" />
									</view>
									<view class="fz28 fgfdgdfgbty">{{item.dictLabel}}</view>
								</view>
							</label>
						</radio-group>
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6 btm">
					<view class="xczvrytxctrtr  vertical-center tl">
						推荐企业:
					</view>
					<view class="z3 flex-1">
						<radio-group class="" @change="kxczxtrty">
							<label class="xzczxctrt mr20">
								<view class="display-flex">
									<view>
										<radio :checked="!dataForm.isGood" :value="false" class="kcxzvxcdrytr" />
									</view>
									<view class="fz28 fgfdgdfgbty">不推荐</view>
								</view>
							</label>
							<label class="xzczxctrt mr20">
								<view class="display-flex">
									<view>
										<radio :checked="dataForm.isGood" :value="true" class="kcxzvxcdrytr" />
									</view>
									<view class="fz28 fgfdgdfgbty">推荐</view>
								</view>
							</label>
						</radio-group>
					</view>
				</view>

				<view class="pt10 pm10 display-flex fz30 z6 btm display-flex">
					公司logo:
					<view class="flex-1 ml20">

						<view class="czxcsderexcr ab vertical-center pr" @tap="kxmcfdf">
							<text class="iconfont icon-14CIRCLE clofdfdtrtrt" @tap.stop="jjmxdsfsd"
								v-if="dataForm.companyImg"> </text>
							<image :src="dataForm.companyImg" class="w100 h100 cz" mode="aspectFill"
								v-if="dataForm.companyImg"></image>
							<text class="iconfont icon-zhaopian xzcertrxcr" v-if="!dataForm.companyImg"></text>
						</view>

					</view>
				</view>
				<view class="pt10 pm10 fz30 z6 btm ">
					头图背景:
					<view class="flex-1  mt20">
						<view class="czxcsderexcr vertical-center pr" @tap="kxmcfdfb">
							<text class="iconfont icon-14CIRCLE clofdfdtrtrt" @tap.stop="jjmxdsfsdb"
								v-if="dataForm.contentImg"> </text>
							<image :src="dataForm.contentImg" class="w100 h100 cz" mode="aspectFill"
								v-if="dataForm.contentImg"></image>
							<text class="iconfont icon-zhaopian xzcertrxcr" v-if="!dataForm.contentImg"></text>
						</view>

					</view>
				</view>
			</view>
		</view>
	</view>
	<view class="kcdxvrtxzty pd pm20 bgff pt20">
		<button type="primary" class="fz32" @tap="querenxftd">确定</button>
	</view>
</template>
<script lang="ts" setup>
	import { ref } from "vue"
	import { hf, hfer, hfsan, dxrequest, VerifyTheLogin, upImg, yzphone, zidianall, callBack } from "@/util/index.js"
	import { onLoad } from "@dcloudio/uni-app"
	const logo = ref()
	const jnxcdfr = ref([])
	const gsid = ref()

	const dataForm = ref({
		companyName: "",//公司名称
		companyImg: "",//logo
		contentImg: "",//头图
		companyAddr: "",//地址
		tag: "",//企业类型
		linkMan: "",// 联系人
		linkManTel: "",//联系人电话
		isGood: true,
		lng: "",
		lat: "",
		content: "" // 简介

	})
	const kxmcfdf = async () => {
		const dhsd = await upImg()
		dataForm.value.companyImg = dhsd.imgurl
	}
	const kxmcfdfb = async () => {
		const dhsd = await upImg()
		dataForm.value.contentImg = dhsd.imgurl
	}
	const jjmxdsfsd = (idx) => {
		dataForm.value.companyImg = ""
	}
	const jjmxdsfsdb = (idx) => {
		dataForm.value.contentImg = ""
	}
	const dimxd = () => {
		uni.chooseLocation({
			success: function (res) {
				console.log('位置名称：' + res.name);
				console.log('详细地址：' + res.address);
				console.log('纬度：' + res.latitude);
				console.log('经度：' + res.longitude);
				dataForm.value.companyAddr = res.address
				dataForm.value.lng = '' + res.longitude
				dataForm.value.lat = '' + res.latitude
			}
		});
	}
	onLoad(async (data) => {
		const comany_tag = await zidianall("comany_tag")
		jnxcdfr.value = comany_tag
		if (data.id) {
			gsid.value = true
			kmxcert(data.id)
			uni.setNavigationBarTitle({
				title: "编辑公司"
			})
		}
	})
	const kmxcert = async (id) => {
		const { data } = await dxrequest("/api/tmcompany/" + id)
		console.log(data)
		dataForm.value = data
	}
	const kxczxtrty = (data) => {
		let kdfddf = JSON.parse(data.detail.value)
		dataForm.value.isGood = kdfddf
	}
	const jxczertet = (data) => {
		dataForm.value.tag = data.detail.value
	}
	const querenxftd = async () => {
		if (!dataForm.value.companyName) {
			uni.showToast({
				icon: "none",
				title: "请输入公司名称"
			})
			return
		}
		if (!dataForm.value.companyAddr) {
			uni.showToast({
				icon: "none",
				title: "请选择公司地址"
			})
			return
		}
		if (!dataForm.value.content) {
			uni.showToast({
				icon: "none",
				title: "请输入公司简介"
			})
			return
		}
		if (!dataForm.value.tag) {
			uni.showToast({
				icon: "none",
				title: "请选择企业类型"
			})
			return
		}
		if (!dataForm.value.isGood) {
			uni.showToast({
				icon: "none",
				title: "请上传企业logo"
			})
			return
		}
		if (!dataForm.value.contentImg) {
			uni.showToast({
				icon: "none",
				title: "请上传头图"
			})
			return
		}
		await dxrequest("/api/tmcompany", dataForm.value, gsid.value ? "put" : "post")
		uni.showToast({
			title: "添加成功！"
		})
		callBack()
	}
</script>

<style scoped>
	.fcvvxxcvyty {
		border: 2rpx solid #e0e0e0;
		border-radius: 8rpx;
		padding: 20rpx;
		font-size: 30rpx !important;
		width: 100%;
	}

	.czxcsderexcr.ab {
		width: 200rpx;
	}
</style>